package com.luxk.db.block;

public interface BlockCacheHeader {
	
	public enum BlockType {
		NONE(0, "none"),
		CONFIG(1, "Configuration file block"),
		META(2, "Meta file block"),
		REDO(3, "Redo log file block"),
		SEGMENT_HEADER(4, "Segment header block"),
		TABLE(5, "Table block"),
		BTREE_INDEX_BRANCH(6, "B+tree index branch block"),
		BTREE_INDEX_LEAF(7, "B+tree index leaf block"),
		LOB(8, "Lob data block"),
		UNDO_HEADER(9, "Undo header block"),
		UNDO(10, "Undo block");
		
		private static final BlockType[] blockTypes = {
			NONE, CONFIG, META,
			REDO,
			SEGMENT_HEADER,
			TABLE,
			BTREE_INDEX_BRANCH, BTREE_INDEX_LEAF,
			LOB,
			UNDO_HEADER, UNDO
		};
		
		private final int type;
		private final String name;
		
		BlockType(int type, String name) {
			this.type = type;
			this.name = name;
		}
		
		public int getType() { return this.type; }
		
		public String getTypeName() { return this.name; }
		
		public char toChar() {
			return (char)this.type;
		}
		
		public static BlockType get(byte val) {
			return blockTypes[val];
		}
	}

	public enum BlockSize {
		NONE(0, 0),
		SIZE_512B(1, 512),
		SIZE_1K(1, 1024),
		SIZE_2K(2, 2048),
		SIZE_4K(3, 4096),
		SIZE_8K(4, 8192),
		SIZE_16K(5, 16384),
		SIZE_32K(6, 32768);
		
		private static final BlockSize[] blockSizes = {
			NONE,
			SIZE_512B,
			SIZE_1K, SIZE_2K, SIZE_4K, SIZE_8K, SIZE_16K, SIZE_32K
		};
		
		private final int sizeType;
		private final int size;
		
		BlockSize(int sizeType, int size) {
			this.sizeType = sizeType;
			this.size = size;
		}
		
		public int getSizeType() { return this.sizeType; }
		
		public int getSize() { return this.size; }
		
		public static BlockSize get(byte val) {
			return blockSizes[val];
		}
	}
	
	/* format
	 * offset  0, 1 byte : block type
	 * offset  1, 1 byte : block size type
	 * offset  2, 4 byte : DBA
	 * offset  6, 8 byte : system change number
	 * offset 14, 1 byte : block change sequence
	 * offset 15, 1 byte : option flags
	 */

	public static final int OFFSET_BLOCK_TYPE = 0;
	public static final int OFFSET_BLOCK_SIZE = 1;
	public static final int OFFSET_DBA = 2;
	public static final int OFFSET_SCN = 6;
	public static final int OFFSET_SEQ = 14;
	public static final int OFFSET_FLAGS = 15;
	
	public int getBlockCacheChecksum();
	
	public BlockType getBlockType();
	public void setBlockType(BlockType type);
	
	public BlockSize getBlockSizeType();
	public void setBlockSizeType(BlockSize size);

	public int getBlockCacheDba() throws Exception;
	public void setBlockCacheDba(int dba) throws Exception;
	
	public long getBlockCacheScn() throws Exception;
	public void setBlockCacheScn(long scn) throws Exception;
	
	public int getBlockCacheSeq();
	public void setBLockCacheSeq(int seq) throws Exception;
	
	public byte getBlockCacheFlags() throws Exception;
	public void setBlockCacheFlags(byte flags);
	
	public int getBlockCacheHeaderSize();
	
	public void format();
}
